package com.yuzhi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @ClassName: SoilClassEnum
 * @Author: Mario
 * @Date: 2024-08-18 16:13
 * @Description: 土壤等级枚举值
 * @ProjectName: drainageapp-area
 * @PackageName: com.yuzhi.common.enums
 */
@Getter
@AllArgsConstructor
public enum SoilClassEnum {
    EXCELLENT("优秀", 90, Double.POSITIVE_INFINITY),
    GOOD("良好", 75, 89),
    AVERAGE("中等", 60, 74),
    POOR("较差", Double.NEGATIVE_INFINITY, 60);

    private final String desc;

    private final double minValue;

    private final double maxValue;
    /**
     * 获取土壤等级描述
     *
     * @param value
     * @return java.lang.String
     * @date: 2024-08-18 16:17:13
     * @author: Mario
     */
    public static String getDesc(double value) {
        return Arrays.stream(values())
                .filter(f -> value >= f.getMinValue() && value < f.getMaxValue())
                .findFirst()
                .map(SoilClassEnum::getDesc)
                .orElseThrow(() -> new IllegalArgumentException("Invalid soil class value"));
    }
}
